﻿Public Class XLNhanVien
    Private nv As New KNNhanVien
    Private dt As New DataTable
    Public Function BUS_LayDSNV() As DataTable
        Return nv.DSNV()
    End Function
    Public Function BUS_ArrDSNV() As ArrayList
        Dim ds As New ArrayList
        dt = nv.DSNV()
        For Each dr As DataRow In dt.Rows
            Dim n As New DTO_NhanVienCT.NhanVien
            n.MaNV = dr("MaNV")
            n.HoTen = dr("HoTen")
            n.ChucVu = dr("CVu")
            ds.Add(n)
        Next
        Return ds
    End Function
    Public Function BUS_DKArrNV(ByVal str As String) As ArrayList
        Dim ds As New ArrayList
        dt = nv.DKDSNV(str)
        For Each dr As DataRow In dt.Rows
            Dim n As New DTO_NhanVienCT.NhanVien
            n.MaNV = dr("MaNV")
            n.HoTen = dr("HoTen")
            ds.Add(n)
        Next
        Return ds
    End Function
    Public Function BUS_SaveNV(ByVal data As DataTable) As Boolean
        Return nv.SaveNV(data)
    End Function
    Public Sub BUS_Add_Up_NV(ByRef dr As DataRow, ByVal nv_ As DTO_NhanVienCT.NhanVien)
        dr("MaNV") = nv_.MaNV
        dr("HoTen") = nv_.HoTen
        dr("NgaySinh") = nv_.NgaySinh
        dr("GioiTinh") = nv_.GioiTinh
        dr("NoiSinh") = nv_.NoiSinh
        dr("NguyenQuan") = nv_.NguyenQuan
        dr("CMND") = nv_.CMND
        dr("NgayCap") = nv_.NgayCap
        dr("NoiCap") = nv_.NoiCap
        dr("DienThoai") = nv_.DienThoai
        dr("DCTTru") = nv_.DiaChi
        dr("DanToc") = nv_.DanToc
        dr("TonGiao") = nv_.TonGiao
        dr("TrinhDoHocVan") = nv_.HocVan
        dr("BangCap") = nv_.BangCap
        dr("CVu") = nv_.ChucVu
        dr("QTich") = nv_.QuocTich
        dr("NgoaiNgu") = nv_.NgoaiNgu
        dr("Doan") = nv_.VaoDoan
        dr("Dang") = nv_.VaoDang
        dr("TTBThan") = nv_.QTBanThan
        dr("MaPhong") = nv_.BoPhan
        dr("Hinh") = nv_.Hinh
    End Sub
    Public Function BUS_TimMaPB(ByVal str As String, ByVal dspb As List(Of DTO_PhongBan.PhongBan)) As String
        Dim kq As String = ""
        For Each pb As DTO_PhongBan.PhongBan In dspb
            If pb.TenPhong = str Then
                kq = pb.MaPB
            End If
        Next
        Return kq
    End Function
    Public Function BUS_TimNhanVien(ByVal str As String, ByRef maph As String, ByVal data As DataTable, ByVal dspb As List(Of DTO_PhongBan.PhongBan)) As List(Of DTO_NhanVienCT.NhanVien)
        Dim ds As New List(Of DTO_NhanVienCT.NhanVien)
        maph = BUS_TimMaPB(str, dspb)
        For Each dr As DataRow In data.Rows
            If maph = dr("MaPhong") Then
                Dim nv As New DTO_NhanVienCT.NhanVien
                nv.MaNV = dr("MaNV")
                nv.HoTen = dr("HoTen")
                nv.NgaySinh = dr("NgaySinh")
                nv.GioiTinh = dr("GioiTinh")
                nv.NoiSinh = dr("NoiSinh")
                nv.NguyenQuan = dr("NguyenQuan")
                nv.CMND = dr("CMND")
                nv.NgayCap = dr("NgayCap")
                nv.NoiCap = dr("NoiCap")
                nv.DienThoai = dr("DienThoai")
                nv.DiaChi = dr("DCTTru")
                nv.DanToc = dr("DanToc")
                nv.TonGiao = Convert.ToString(dr("TonGiao"))
                nv.HocVan = dr("TrinhDoHocVan")
                nv.BangCap = dr("BangCap")
                nv.ChucVu = Convert.ToString(dr("CVu"))
                nv.QuocTich = dr("QTich")
                nv.NgoaiNgu = Convert.ToString(dr("NgoaiNgu"))
                nv.VaoDoan = Convert.ToString(dr("Doan"))
                nv.VaoDang = Convert.ToString(dr("Dang"))
                nv.QTBanThan = Convert.ToString(dr("TTBThan"))
                nv.BoPhan = dr("MaPhong")
                nv.Hinh = dr("Hinh")
                ds.Add(nv)
            End If
        Next
        Return ds
    End Function
    Public Function BUS_KtraThem(ByVal nv As DTO_NhanVienCT.NhanVien, ByVal data As DataTable, ByVal dau As Integer) As Boolean
        Dim kq As Boolean = False
        If dau = 1 Then
            For Each dr As DataRow In data.Rows
                If dr("MaNV") = nv.MaNV Then
                    kq = True
                    Exit For
                End If
            Next
        End If
        Dim xl As New XLThamSo
        Dim n As String = DateTime.Now.Year
        Dim arr As String() = nv.NgaySinh.Split("/")
        Dim tuoi As Integer = Convert.ToInt32(n) - Convert.ToInt32(arr(2).ToString)
        If tuoi = xl.laytuoi Then kq = True
        If nv.HoTen = "" Then kq = True
        If nv.NoiSinh = "" Then kq = True
        If nv.NguyenQuan = "" Then kq = True
        If nv.CMND = 0 Then kq = True
        If nv.NoiCap = "" Then kq = True
        If nv.QTBanThan = "" Then kq = True
        If nv.DienThoai = 0 Then kq = True
        If nv.DiaChi = "" Then kq = True
        If nv.HocVan = "" Then kq = True
        If nv.Hinh = "" Then kq = True
        If nv.QuocTich = "" Then kq = True
        Return kq
    End Function
    Public Function BUS_SLManv(ByVal str As String) As String
        Dim a As String = str.Substring(0, 2)
        Dim b As String = str.Substring(2)
        Dim i As Integer = Convert.ToUInt32(b) + 1
        'i += 1
        b = "00000000" & i
        If b.Length > 8 Then
            For j As Integer = 1 To b.Length
                b = b.Substring(1)
                If b.Length = 8 Then
                    Exit For
                End If
            Next
        End If
        a = a & b
        Return a
    End Function
    
    Public Function BUS_AddTreePB(ByVal str As String, ByVal mapb As String, ByVal data As DataTable) As TreeNode
        Dim tr As New TreeNode(str)
        For Each dr As DataRow In data.Rows
            If dr("MaPhong") = mapb Then
                Dim nv As New DTO_NhanVienCT.NhanVien
                nv.MaNV = dr("MaNV")
                nv.HoTen = dr("HoTen")
                nv.NgaySinh = dr("NgaySinh")
                nv.GioiTinh = dr("GioiTinh")
                nv.NoiSinh = dr("NoiSinh")
                nv.NguyenQuan = dr("NguyenQuan")
                nv.CMND = dr("CMND")
                nv.NgayCap = dr("NgayCap")
                nv.NoiCap = dr("NoiCap")
                nv.DienThoai = dr("DienThoai")
                nv.DiaChi = dr("DCTTru")
                nv.DanToc = dr("DanToc")
                nv.TonGiao = Convert.ToString(dr("TonGiao"))
                nv.HocVan = dr("TrinhDoHocVan")
                nv.BangCap = dr("BangCap")
                nv.ChucVu = Convert.ToString(dr("CVu"))
                nv.QuocTich = dr("QTich")
                nv.NgoaiNgu = Convert.ToString(dr("NgoaiNgu"))
                nv.VaoDoan = Convert.ToString(dr("Doan"))
                nv.VaoDang = Convert.ToString(dr("Dang"))
                nv.QTBanThan = Convert.ToString(dr("TTBThan"))
                nv.BoPhan = dr("MaPhong")
                nv.Hinh = dr("Hinh")
                tr.Nodes.Add(BUS_AddTreeNV(nv))
            End If
        Next
        tr.Tag = str
        Return tr
    End Function
    Public Function BUS_AddTreeNV(ByVal nv As DTO_NhanVienCT.NhanVien) As TreeNode
        Dim tr As New TreeNode(nv.HoTen)
        tr.Nodes.Add(nv.MaNV)
        tr.Nodes.Add(nv.NgaySinh)
        tr.Nodes.Add(nv.GioiTinh)
        tr.Nodes.Add(nv.NoiSinh)
        tr.Nodes.Add(nv.NguyenQuan)
        tr.Nodes.Add(nv.CMND)
        tr.Nodes.Add(nv.NgayCap)
        tr.Nodes.Add(nv.NoiCap)
        tr.Nodes.Add(nv.DienThoai)
        tr.Nodes.Add(nv.DiaChi)
        tr.Nodes.Add(nv.DanToc)
        tr.Nodes.Add(nv.TonGiao)
        tr.Nodes.Add(nv.HocVan)
        tr.Nodes.Add(nv.BangCap)
        tr.Nodes.Add(nv.ChucVu)
        tr.Nodes.Add(nv.QuocTich)
        tr.Nodes.Add(nv.NgoaiNgu)
        tr.Nodes.Add(nv.VaoDoan)
        tr.Nodes.Add(nv.VaoDang)
        tr.Nodes.Add(nv.QTBanThan)
        tr.Nodes.Add(nv.BoPhan)
        tr.Nodes.Add(nv.Hinh)
        tr.Tag = nv
        Return tr
    End Function
End Class

